/**
 * author:Administrator
 * date:2015/7/27
 * desc:TODO
 */

'use strict';
var debugLog = require('./function.js').debugLog;
console.log('Load O2O: ' + module.id);

let F = require('./function');
let Dao = require('./dao');

let daoDispatcher = require('./dao/permission.js');

var api = {};
exports.api = api;

/***
 * 添加权限, 并非向某个角色添加权限
 * post /o2o_service/permission/v1/addBatch
 {  act:1 ,
    list: {
        "商家管理": ["添加商家","编辑商家"],
        "商家详情": ["商家详情"]
    }
 }
 * @param Env
 */
api.addBatch = function*(Env) {
    Env.I = yield F.Init(Env, [1]);
    if (Env.I.errors) {
        return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
    }
    var fields = Env.I;

    let result = yield daoDispatcher.addBatch(fields.list);
    return F.returnMsg(200, 'OK', 3, result);
};

/**
 * 获取所有权限列表
 * post /o2o_service/permission/v1/getAll
 {
     "act": 1
 }
 */
api.getAll = function*(Env) {
    Env.I = yield F.Init(Env, [1]);
    if (Env.I.errors) {
        return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
    }
    let result = yield daoDispatcher.getAll();
    return F.returnMsg(200, 'OK', 3, result);
};

